/*
 * @Author: Ma Xiaohan
 * @Date: 2018-08-19 16:15:59
 * @Last Modified by: Xiaohan Ma
 * @Last Modified time: 2018-08-31 18:30:55
 */
const assert = require('assert');
const BasicController = require('../BasicController.js');

module.exports = class extends BasicController {
  constructor(ctx) {
    super(ctx);
    assert(think.isFunction(this.model), 'this.model must be a function');
    this.MODEL = this.ctx.state.ApiInfo.model;
    this.params = {
      model: this.MODEL,
      data: this.post()
    };
  }
  // 前台展示接口
  async getlistAction() {
    const params = this.params;
    const list = await this.model(params.model).getlistAction();
    const display = list.filter(element => {
      let richtext = element.richtext;
      if (think.isEmpty(richtext)) {
        richtext = '';
      } else {
        richtext = richtext.richtext.toString('utf-8');
      }
      element.richtext = richtext;
      return element.status === 1;
    });
    return this.success(display, '获取成功');
  }
};

/**
 * @api {get} /recruit_new_info/recruit_new_info/get /get
 * @apiDescription 根据id查询单个招新信息
 * @apiGroup recruit_new_info
 * @apiParam {String} id  招新信息ID
 *
 *
 * @apiParamExample {string} 请求参数格式:
 *    ?id=8b3a12bd-6195-403b-9fcc-a6a053d6d073
 *
 * @apiVersion 1.0.0
 * @apiErrorExample {json} 错误返回值:
 *{
 *   "code": 1001,
 *   "msg": {
 *      "id": "id can not be blank"
 *   }
 *}
 * @apiSuccessExample {json} 正确返回值:
{
    "code": 0,
    "msg": "",
    "data": {
        "id": "e412850d-59f3-4d73-b9bf-07206de85b4b",
        "email": "14446176563@qq.com",
        "recruit_start_time": "2018-08-11",
        "recruit_end_time": "2018-09-03",
        "title":"这是招新信息标题"，
        "status": 1,
        "filesinfo": [],
        "richtext": "<p>asdsasafsa</p>"
    }
}
 */

/**
 * @api {delete} /recruit_new_info/recruit_new_info/del /del
 * @apiDescription 根据id删除招新信息
 * @apiGroup recruit_new_info
 *
 * @apiParam {String} id 招新信息ID
 *
 *
 * @apiParamExample {object} 请求参数格式:
 *  {
 * id: dda33412-8e95-40f9-92f5-f01df8dd2d21,
 * }
 *
 * @apiVersion 1.0.0
 * @apiErrorExample {json} 错误返回值:
 * {
 * "code": 1001,
 * "msg": {
 *      "id": "id can not be blank"
 *  }
 * }
 * @apiSuccessExample {json} 正确返回值:
 * {
 *  "code": 0,
 *  "msg": "",
 *  "data": 1
 * }
 */

/**
 * @api {post} /recruit_new_info/recruit_new_info/edit /edit
 * @apiDescription 根据id修改招新信息
 * @apiGroup recruit_new_info
 *
 * @apiParam {String} id 招新信息id
 * @apiParam {String} richtext 富文本内容
 * @apiParam {String} [title] 招新信息标题
 * @apiParam {String} [status] 招新信息状态 0保存，1发布
 * @apiParam {String} [recruit_end_time] 招新结束时间
 * @apiParam {String} [email] 报名表投递邮箱
 * @apiParam {String} [recruit_start_time] 招新开始时间
 *
 * @apiParamExample {object} 请求参数格式:
 *  {
 *  id: '18d92789-0240-4878-9b94-41078f2dbd50',
 *  email: '2776199922@qq.com',
 * }
 *
 * @apiVersion 1.0.0
 * @apiErrorExample {json} 错误返回值:
 * {
 * "code": 1001,
 * "msg": {
 *      "id": "id can not be blank"
 *  }
 * }
 * @apiSuccessExample {json} 正确返回值:
 *{
 *   "errno": 0,
 *   "errmsg": "",
 *   "data": 1
*}
*/

/**
 * @api {POST} /recruit_new_info/recruit_new_info/listall /listall
 * @apiDescription 获取全部招新信息列表/根据条件获取招新信息列表
 * @apiGroup recruit_new_info
 *
 *
 * @apiParam {String} [status] 招新信息状态 0保存，1发布
 * @apiParam {String} [recruit_end_time] 招新结束时间
 * @apiParam {String} [email] 报名表投递邮箱
 * @apiParam {String} [recruit_start_time] 招新开始时间
 * @apiParam {String} [title] 招新信息标题
 *
 *
 * @apiVersion 1.0.0
 * @apiErrorExample {json} 错误返回值:
 *     {
 *        "code": ,
 *        "msg": "获取失败",
 *        "error": {
 *        },
 *     }
 *
 * @apiSuccessExample {json} 正确返回值:
{
    "code": 0,
    "msg": "",
    "data": [
        {
            "id": "6eae97f9-c81d-4dd8-b370-c057974007f5",
            "email": "151625+62@qq.com",
            "recruit_start_time": "2018-08-11",
            "title":"这是招新信息标题"，
            "recruit_end_time": "2018-09-03",
            "status": 0
        },
        {
            "id": "7bd09115-df94-4048-a9e5-7ce2ed786b63",
            "email": "151625+62@qq.com",
            "title":"这是招新信息标题"，
            "recruit_start_time": "2018-08-11",
            "recruit_end_time": "2018-09-03",
            "status": 0
        },
        {
            "id": "e412850d-59f3-4d73-b9bf-07206de85b4b",
            "email": "14446176563@qq.com",
            "title":"这是招新信息标题"，
            "recruit_start_time": "2018-08-11",
            "recruit_end_time": "2018-09-03",
            "status": 1,
            "richtext": "<p>asdsasafsa</p>"
        }
    ]
}
 */

/**
 * @api {POST} /recruit_new_info/recruit_new_info/listpage /listpage
 * @apiDescription 获取全部招新信息列表/根据条件分页获取招新信息列表
 * @apiGroup recruit_new_info
 *
 * @apiParam {String} [title] 招新信息标题
 * @apiParam {String} [status] 招新信息状态 0保存，1发布
 * @apiParam {String} [recruit_end_time] 招新结束时间
 * @apiParam {String} [email] 报名表投递邮箱
 * @apiParam {String} [recruit_start_time] 招新开始时间
 * @apiParam {Number} [page] 页数
 * @apiParam {Number} [pageSize] 数据条数
 *
 *
 * @apiParamExample {get} Request-Example:
                 {
                   page:1,
                   pageSize:10,
                   project_start_time:2018-08-09
                  }
 * @apiVersion 1.0.0
 * @apiErrorExample {json} 错误返回值:
 *     {
 *        "code": ,
 *        "msg": "获取失败",
 *        "error": {
 *        },
 *     }
 *
 * @apiSuccessExample {json} 正确返回值:
{
    "code": 0,
    "msg": "",
    "data": {
        "pageSize": 20,
        "current": 1,
        "pages": 1,
        "total": 3,
        "data": [
            {
                "id": "6eae97f9-c81d-4dd8-b370-c057974007f5",
                "email": "151625+62@qq.com",
                "recruit_start_time": "2018-08-11",
                "recruit_end_time": "2018-09-03",
                "title":"这是招新信息标题"，
                "status": 0
            },
            {
                "id": "7bd09115-df94-4048-a9e5-7ce2ed786b63",
                "email": "151625+62@qq.com",
                "recruit_start_time": "2018-08-11",
                "recruit_end_time": "2018-09-03",
                "title":"这是招新信息标题"，
                "status": 0
            },
            {
                "id": "e412850d-59f3-4d73-b9bf-07206de85b4b",
                "email": "14446176563@qq.com",
                "recruit_start_time": "2018-08-11",
                "recruit_end_time": "2018-09-03",
                "title":"这是招新信息标题"，
                "status": 1,
                "richtext": "<p>asdsasafsa</p>"
            }
        ]
    }
}
 */

/**
 * @api {POST} /recruit_new_info/recruit_new_info/add /add
 * @apiDescription 新增招新信息
 * @apiGroup recruit_new_info
 *
 *
 *
 * @apiParam {String} title 招新信息标题
 * @apiParam {String} [richtext] 富文本内容
 * @apiParam {String} status 招新信息状态 0保存，1发布
 * @apiParam {String} recruit_end_time 招新结束时间
 * @apiParam {String} [email] 报名表投递邮箱
 * @apiParam {String} [recruit_start_time] 招新开始时间
 *
 * @apiVersion 1.0.0
 * @apiErrorExample {json} 错误返回值:
 {
    "code": 1001,
    "msg": {
        "title": "title can not be blank"
        "recruit_end_time": "recruit_end_time can not be blank",
        "status": "status can not be blank"
    }
}
 *
 * @apiSuccessExample {json} 正确返回值:
{
    "code": 0,
    "msg": "",
    "data": {
        "id": "6eae97f9-c81d-4dd8-b370-c057974007f5"
    }
}
 */

/**
 * @api {POST} /recruit_new_info/recruit_new_info/getlist /getlist 前台获取招新信息数据列表
 * @apiDescription 获取全部招新信息列表/根据条件分页获取招新信息列表
 * @apiGroup recruit_new_info
 *
 * @apiParam {String} [title] 招新信息标题
 * @apiParam {String} [status] 招新信息状态 0保存，1发布
 * @apiParam {String} [recruit_end_time] 招新结束时间
 * @apiParam {String} [email] 报名表投递邮箱
 * @apiParam {String} [recruit_start_time] 招新开始时间
 * @apiParam {Number} [page] 页数
 * @apiParam {Number} [pageSize] 数据条数
 *
 *
 *  * @apiParamExample {get} Request-Example:
                 {
                  }
 * @apiVersion 1.0.0
 * @apiErrorExample {json} 错误返回值:
 *     {
 *        "code": ,
 *        "msg": "获取失败",
 *        "error": {
 *        },
 *     }
 *
 * @apiSuccessExample {json} 正确返回值:
{
    "code": 0,
    "msg": "获取成功",
    "data": [
        {
            "id": "23f9e18d-7fbc-409d-94c9-fdec120ed3d0",
            "title": "1",
            "email": "2575397068@qq.com",
            "recruit_start_time": "2018-08-26",
            "recruit_end_time": "2018-08-28",
            "status": 1,
            "create_time": "2018-08-26 21:18:38",
            "update_time": "2018-08-26 21:18:48",
            "introduction_files": [],
            "richtext": "<p>1</p>"
  *      }
 *   ]
*}
 */
